package thread.multi;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ThreadPool {

    public static void main(String[] args) {
        //1.创建服务，创建线程池
        //Executors.newFixedThreadPool(int num)参数为线程池大小
        ExecutorService service = Executors.newFixedThreadPool(10);

        //2.执行任务
        service.execute(new MyThread());
        service.execute(new MyThread());
        service.execute(new MyThread());
        service.execute(new MyThread());
        service.execute(new MyThread());

        //3.关闭服务
        service.shutdown();
    }
}

class MyThread implements Runnable{
    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            System.out.println(Thread.currentThread().getName()+"-num-"+i);
        }
    }
}